package com.stock.stock.modules.sys.service.impl;


import com.stock.stock.utils.Query;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stock.stock.modules.sys.dao.StockListDao;
import com.stock.stock.modules.sys.entity.StockListEntity;
import com.stock.stock.modules.sys.service.StockListService;


@Service("stockListService")
public class StockListServiceImpl extends ServiceImpl<StockListDao, StockListEntity> implements StockListService {

    @Autowired(required = false)
    StockListDao stockListDao;

    @Override
    public List<StockListEntity> queryPage(Map<String, Object> params) {

        QueryWrapper<StockListEntity> query = new QueryWrapper<StockListEntity>();
        String tmp = "";
        tmp = (String) params.get("id");
        query.eq(StringUtils.isNotBlank(tmp), "id", tmp);
        tmp = (String) params.get("tradingDay");
        query.eq(StringUtils.isNotBlank(tmp), "trading_day", tmp);
        tmp = (String) params.get("gridTime");
        query.eq(StringUtils.isNotBlank(tmp), "grid_time", tmp);
        tmp = (String) params.get("acctId");
        query.eq(StringUtils.isNotBlank(tmp), "acct_id", tmp);
        tmp = (String) params.get("symbol");
        query.eq(StringUtils.isNotBlank(tmp), "symbol", tmp);
        tmp = (String) params.get("symbolType");
        query.eq(StringUtils.isNotBlank(tmp), "symbol_type", tmp);
        tmp = (String) params.get("pnlToday");
        query.eq(StringUtils.isNotBlank(tmp), "pnl_today", tmp);
        tmp = (String) params.get("pnlHold");
        query.eq(StringUtils.isNotBlank(tmp), "pnl_hold", tmp);
        tmp = (String) params.get("pnlTrade");
        query.eq(StringUtils.isNotBlank(tmp), "pnl_trade", tmp);

        IPage<StockListEntity> page = stockListDao.selectPage(new Query<StockListEntity>().getPage(params),
                query);

        return page.getRecords();
    }

    @Override
    public List<StockListEntity> getDay(Map<String, Object> params) {
        QueryWrapper<StockListEntity> query = new QueryWrapper<StockListEntity>();
        String tmp = "";
        tmp = (String) params.get("beginDate");
        query.ge(StringUtils.isNotBlank(tmp), "trading_day", tmp);
        tmp = (String) params.get("endDate");
        query.le(StringUtils.isNotBlank(tmp), "trading_day", tmp);
        tmp = (String) params.get("symbol");
        query.eq(StringUtils.isNotBlank(tmp), "symbol", tmp);
        tmp = (String) params.get("acctId");
        query.eq(StringUtils.isNotBlank(tmp), "acct_id", tmp);
        return stockListDao.getDay(query);

    }

    @Override
    public List<StockListEntity> getTime(Map<String, Object> params) {
        QueryWrapper<StockListEntity> query = new QueryWrapper<StockListEntity>();
        String tmp = "";
        tmp = (String) params.get("tradingDay");
        query.eq(StringUtils.isNotBlank(tmp), "trading_day", tmp);
        tmp = (String) params.get("symbol");
        query.eq(StringUtils.isNotBlank(tmp), "symbol", tmp);
        tmp = (String) params.get("acctId");
        query.eq(StringUtils.isNotBlank(tmp), "acct_id", tmp);
        return stockListDao.getTime(query);

    }

}
